<?php
namespace app\mp\admin;
use app\system\admin\Admin;
use think\Db;
use app\common\service\StallFeed as StallFeedService;
use app\common\service\StallCost as StallCostService;
class StallCost extends Admin
{
	/**
     * 费用单记录
     *
     * @author 飞燕
     * @date 2020年3月18日
     *
     */
    public function stallCostDetail()
    {
    	$stallFeedId  = $this->request->param('stall_feed_id/d', 0);
    	if ($this->request->isAjax()) {
			$stallCostService=new StallCostService();
    		$where      = $data = [];
//    		$page       = $this->request->param('page/d', 1);
//    		$limit      = $this->request->param('limit/d', 20);
    		$list = $stallCostService->getListByStallFeedId($stallFeedId);
    		$data['count'] = count($list);
    		$data['data'] = $list;
    		$data['code'] = 0;
    		$data['msg'] = '';
    		return json($data);
    	}

    	$assign = [
    		'stallFeedId' => $stallFeedId
    	];
    	return $this->assign($assign)->fetch();
    }
	/**
     * 添加费用单
     *
     * @author 飞燕
     * @date 2021年3月17日
     */
	public function add(){
		$stallFeedId  = $this->request->param('stall_feed_id/d', 0);
		$stallFeedService=new StallFeedService();
		$stInfo = $stallFeedService->getInfoById($stallFeedId);
		if(!$stInfo) return $this->error('参数异常');
		if ($this->request->isPost()) {
			$postData = $this->request->post();
			$postData['stall_feed_id']=$stallFeedId;
			$postData['create_time']=$postData['update_time']= time();
			$id=db('stall_cost')->insertGetId($postData);
			if (!$id) {
    			return $this->error('保存失败');
    		}
    		$this->addOrderLog($stInfo['order_id'], $stInfo['client_ordernum'], "添加物料[".getMaterialName($stInfo['material_id'])."]费用单");
    		return $this->success('保存成功', '');
		}
		$assign = [
			'stall_feed_id'=>$stallFeedId
    	];
    	return $this->assign($assign)->fetch();
	}
}

